package cn.com.open.ms.ecgpaasdatarest.service;

import cn.com.open.ms.ecgpaasdatarest.databasemodel.DataBaseSource;
import cn.com.open.ms.ecgpaasdatarest.enums.DeleteStatus;
import cn.com.open.ms.ecgpaasdatarest.mapper.AppMapper;
import cn.com.open.ms.ecgpaasdatarest.mapper.BusinessDataSourceMapper;
import cn.com.open.ms.ecgpaasdatarest.utils.GsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description
 * @Author 奶茶
 * Created by on 2018/11/30 10:13.
 */
@Service
public class AppService {


    @Autowired
    private AppMapper appMapper;
    @Autowired
    private BusinessDataSourceMapper businessDataSourceMapper;

    /**
     * 根据应用标示查询
     * @param appKey
     * @return
     */
    public String findAppSecretByAppKey(String appKey,String businessName,String tableName){
        return appMapper.findAppSecretByAppkey(appKey,businessName,tableName, DeleteStatus.NO.getPrefix());
    }

    /**
     * 获取数据源信息
     * @param appKey
     * @param businessName
     * @return
     */
    public DataBaseSource getDataSourceInfo(String appKey,String businessName){
        String dataSourceJson = businessDataSourceMapper.getDataSourceInfoByAppKeyAndBusinessName(appKey, businessName, DeleteStatus.NO.getPrefix());
        return GsonUtil.fromJsonToObject(dataSourceJson, DataBaseSource.class);
    }

}
